#include <iostream>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cstdio>
using namespace std;
int N;
typedef pair<int, int> range;

struct cmp {
    bool operator()(const range & r1, const range & r2) {
        return r1.first < r2.first;
    }
};

struct cmpp {
    bool operator()(const range & r1, const range & r2) {
        return r1.second > r2.second;
    }
};

priority_queue<int, vector<range>, cmpp> q;
vector<range> ranges;

void solve();
int main() {
    // freopen("in.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    scanf("%d", &N);
    int x, y;
    while (N--) {
       scanf("%d %d", &x, &y);
        ranges.push_back({x, y});
    }
    solve();
}

void solve() {
    sort(ranges.begin(), ranges.end(), cmp());
    int res = 1; q.push(ranges[0]);
    for (int i = 1; i < ranges.size(); i++) {
        range x = ranges[i];
        range t = q.top(); q.pop();
        if (x.first > t.second) {
            t.second = x.second;
            q.push(t);
        } else {
            q.push(x);
            q.push(t);
            res++;
        }

    }
    printf("%d\n", res);
}